const dbutils = require('./dbutils');

function queryAllStudent(success) {
  success({age: 30, height: 165, weight: 62});
  return;
  
  let querySql = 'select * from student;';
  let connection = dbutils.createConnection();
  connection.connect();
  connection.query(querySql, (err, res) => {
    if (err == null) {
      console.log(res);
      success(res);
    } else {
      throw new Error(err);
    }
  });
  connection.end();
}

// 添加 传递参数
function insertStudent(sunNum, stuName, stuClass, age, success) {
  
  success({sunNum, stuName, stuClass, age});
  return;
  
  let insertSql = 'insert into student (sunNum, stuName, stuClass, age) values (?, ?, ?, ?);';
  let connection = dbutils.createConnection();
  let params = [sunNum, stuName, stuClass, age];
  connection.connect();
  connection.query(insertSql, params, (err, res) => {
    if (err == null) {
      console.log(res);
      success(res);
    } else {
      throw new Error(err);
    }
  });
  connection.end();
}


module.exports = {
  queryAllStudent,
  insertStudent
};